# Gilardi, Fabrizio, "The Temporary Importance of Role Models for Women's Political Representation", American Journal of Political Science
# Code to replicate Figures in Section SI2 (Switzerland in comparative perspective)
# gilardi@ipz.uzh.ch, 2014-06-24

# Set working directory
setwd("../Data/")

# Load data
tk <- read.csv("quotas.csv") # Tripp & Kang (2008) CPS
km <- read.csv("sf99femdata.csv") # Kenworthy & Malami (1999) Social Forces
r <- read.csv("ruedin.csv") # Ruedin (2012)



# Tripp & Kang

out.tk <- lm(rep2006 ~ quota + nyrrun + as.factor(fh01) + prelect + edsec + gdp01pcln + other + cathdom  + musdom + me + westeu + africa + asia + easteu + america + pacific, data=tk)
summary(out.tk)

tk$pred <- predict(out.tk)

#pdf(file="tripp-kang.pdf", paper="special", width=6, height=5.5)
par(mar=c(3.6,3.5,2,1), mgp=c(2.5,0.8,0), cex.axis=1.2, cex.lab=1.2, font.main=1)
plot(range(tk$pred), range(tk$rep2006), type="n", ylab="Actual % of women in parliament (2006)", xlab="Predicted % of women in parliament", axes=F)
axis(1)
axis(2)
text(tk$pred[tk$country!="Switzerland"], tk$rep2006[tk$country!="Switzerland"], tk$country[tk$country!="Switzerland"], cex=0.8, col="gray")
text(tk$pred[tk$country=="Switzerland"], tk$rep2006[tk$country=="Switzerland"], tk$country[tk$country=="Switzerland"], cex=1, col=1)
abline(a=0,b=1, lty=2)
legend("topleft", pch=c(), legend="Based on Tripp & Kang (2008)", pt.cex=1.5, cex=1.2, bty="n")
#dev.off()



# Kenworthy & Malami

out.km <- lm(FEMLEGIS ~ ELECSYST + FEMSUFRG + DEMOC + MARXLEN + FEMEDUC + FEMLABOR + GDPPC + REL.CATH + REL.ISLM + REL.OTHR + RATIFIC + ABORTLEG + REG.AFRI + REG.MIDE + REG.ASIA + REG.LATA + REG.EEUR -COUNTRY, data=km, subset=c(FILT146==1))
summary(out.km)

m.km <- model.frame(out.km)
m.km$pred <- predict(out.km)


#pdf(file="kenworthy-malami.pdf", paper="special", width=6, height=5.5)
par(mar=c(3.6,3.5,2,1), mgp=c(2.5,0.8,0), cex.axis=1.2, cex.lab=1.2, font.main=1)
plot(range(m.km$pred), range(m.km$FEMLEGIS), type="n", ylab="Actual % of women in parliament (1998)", xlab="Predicted % of women in parliament", axes=F)
axis(1)
axis(2)
text(m.km$pred[m.km$COUNTRY!="Switzerland"], m.km$FEMLEGIS[m.km$COUNTRY!="Switzerland"], m.km$COUNTRY[m.km$COUNTRY!="Switzerland"], cex=0.8, col="gray")
text(m.km$pred[m.km$COUNTRY=="Switzerland"], m.km$FEMLEGIS[m.km$COUNTRY=="Switzerland"], m.km$COUNTRY[m.km$COUNTRY=="Switzerland"], cex=1, col=1)
abline(a=0,b=1, lty=2)
legend("topleft", pch=c(), legend="Based on Kenworthy & Malami (1999)", pt.cex=1.5, cex=1.2, bty="n")
#dev.off()


# Ruedin

r$women <- r$women*100

quantile(r$women, seq(0,1,0.05))
quantile(r$women[r$reg_EUR==1], seq(0,1,0.05))
r$women[r$Country=="Switzerland"]

out.r <- lm(women ~ el_sys_2 + quota_p + quota_s + age_dem + FH_PR + as.factor(region) -Country, data=r)
summary(out.r)

m.r <- model.frame(out.r)
m.r$pred <- predict(out.r)

#pdf(file="ruedin.pdf", paper="special", width=6, height=5.5)
par(mar=c(3.6,3.5,2,1), mgp=c(2.5,0.8,0), cex.axis=1.2, cex.lab=1.2, font.main=1)
plot(range(m.r$pred), range(m.r$women), type="n", ylab="Actual % of women in parliament (2006)", xlab="Predicted % of women in parliament", axes=F)
axis(1)
axis(2)
text(m.r$pred[m.r$Country!="Switzerland"], m.r$women[m.r$Country!="Switzerland"], m.r$Country[m.r$Country!="Switzerland"], cex=0.8, col="gray")
text(m.r$pred[m.r$Country =="Switzerland"], m.r$women[m.r$Country =="Switzerland"], m.r$Country[m.r$Country =="Switzerland"], cex=1, col=1)
abline(a=0,b=1, lty=2)
legend("topleft", pch=c(), legend="Based on Ruedin (2012)", pt.cex=1.5, cex=1.2, bty="n")
#dev.off()





